<?php
/**
*   意见反馈
*/
namespace app\api\model;
use think\Model;

class Feedback extends Model
{
    /**
    *   列表
    */
    public function _list($where, $order_by="created desc", $page_size = PAGE_SIZE_API){
        $data = $this->where($where)
            ->order($order_by)
            ->paginate($page_size)
            ->toArray();
        return $data;
    }
    
    /**
    * 添加意见
    */
    public function _create($tel, $content){
        if(!preg_match("/^(13|14|15|16|17|18|19)/", $tel)){
            $this->error = '请输入合法的手机号';
            return false;
        }
        if(mb_strlen($content) > 100){
            $this->error = '内容不能超过100个字符';
            return false;
        }
        $content = filterXss($content);
        $data = [
            'tel' => $tel,
            'content' => $content,
            'created' => time()
        ];
        
        $ret = $this->save($data);
        if(!$ret){
            $this->error = '反馈失败';
            return false;
        }
        
        return true;
    }
    

}